home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
ms_dos
/
txf
/
src
/
txfex_s.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
3KB
|
142 lines
/***************
*
* g:\exe\txf\src\txfex_s.c
*/
#include "txf.h"
/********************old_exchange()***************************/
void old_exchange(char *st1,char *st2, char *oldfile, char *newfile)
{ /* old→new */
FILE *tmpin, *tmpout;
int i = 0, clum = 0, knj = 0;
int oldlen = strlen(st1), newlen = 0, chr = NUL;
int chrattr = CT_ANK;
char *old = NULL, *oldattr, *new = NULL;
old = ftrans(st1);
oldlen = strlen(old);
oldattr = malloc(oldlen + 1);
if (oldattr == NULL) {
errexit("cannot use enough memory(oldattr)");
}
for (i = 0; *(old + i) != NUL; i++) {
chrattr = chkctype(*(old + i), chrattr);
*(oldattr + i) = chrattr;
}
if (st2 != NULL) {
new = ftrans(st2);
}
if (new != NULL) {
newlen = strlen(new);
}
if (*inputfile != NUL) {
tmpin = fopen(oldfile,"rb");
}
else {
tmpin = stdin;
}
tmpout = fopen(newfile, "wb");
if (viewmode > 2) {
fprintf(stderr, "Info:readfile=%s,(%d)/writefile=%s,(%d)\n",
oldfile, tmpin, newfile, tmpout);
}
if ((tmpin == NULL) || (tmpout == NULL)) {
errexit("cannot open TMP/input file(exchange-S)\n");
}
if (viewmode > 1) fprintf(stderr, "'%s'→'%s'\n", old, new);
i = 0;
chrattr = CT_ANK;
while (chr != EOF) {
while (i < oldlen) {
chr = getc(tmpin);
if (chr == RET) {
clum = 0;
quote = 0;
}
else {
clum++;
}
if (knj > 0) {
if (clum == 2 && jstrchr(kq, chr| knj<<8) != NULL) {
quote = 1;
}
}
else {
if ((clum == 1) && (jstrchr(kq, (chr & 0x0ff)) != NULL)) {
quote = 1;
}
}
chrattr = chkctype(chr, chrattr);
if (chrattr == CT_KJ1) {
knj = chr;
}
else {
knj = 0;
}
if ((chr == *(old + i)) && (chrattr == *(oldattr + i)) &&
!(quote & quoteflg)) {
i++;
}
else {
if (i > 0) {
fwrite(old, 1, i, tmpout);
i = 0;
}
if ((i == 0) && (chr != EOF)) {
putc(chr,tmpout);
}
}
if (chr == EOF) break;
}
if (i >= oldlen) {
if (newlen > 0) {
fwrite(new, 1, newlen, tmpout);
}
}
else {
fwrite(old, 1, i, tmpout);
}
i = 0;
}
fclose(tmpin);
fclose(tmpout);
free(new);
free(old);
free(oldattr);
if (new != NULL) {
free(new);
}
}
void old_exchangedriver()
{
int i;
char *tmpinname, *tmpoutname;
tmpinname = ((tmpinfile == -1) ? inputfile : tfile[tmpinfile]);
tmpoutname = tfile[((tmpinfile > 0) ? 0 : 1)];
if (viewmode > 0) {
fprintf(stderr, "TXF Tiny exchange module.(Series) Ver1.01\n");
}
if (exold[0] != NULL) {
old_exchange(exold[0], exnew[0], tmpinname, tmpoutname);
}
tmpinfile = ((tmpinfile > 0) ? 0 : 1);
tmpinname = tfile[tmpinfile];
tmpoutname = tfile[1 - tmpinfile];
for (i = 1; i < exflg; i++) {
old_exchange(exold[i], exnew[i], tmpinname, tmpoutname);
tmpinfile = 1 - tmpinfile;
tmpinname = tfile[tmpinfile];
tmpoutname = tfile[1 - tmpinfile];
}
}
/****************end of old_exchange()************************/